home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP12.ZIP
/
PATRON
/
IUILINK.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-19
|
13KB
|
513 lines
/*
* IUILINK.CPP
*
* Implementation of an object with the IOleUILinkContainer interface
* necessary to use the Links Dialog in OLE2UI. This is implemented as
* a stand-along object with access to the CPage with which its associated,
* primiarily because it is only used for the one dialog. Therefore this
* object has it's own IUnknown. In addition, we use the Links Assistant
* object developed in this chapter to simplify our own code.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
/*
* CIOleUILinkContainer::CIOleUILinkContainer
* CIOleUILinkContainer::~CIOleUILinkContainer
*
* Parameters (Constructor):
* pPage LPPAGE of the page we're in.
*/
CIOleUILinkContainer::CIOleUILinkContainer(LPPAGE pPage)
{
m_cRef=0;
m_pPage=pPage;
m_iTenant=0;
m_pDelIUILinks=NULL;
m_fDirty=FALSE;
return;
}
CIOleUILinkContainer::~CIOleUILinkContainer(void)
{
if (NULL!=m_pDelIUILinks)
m_pDelIUILinks->Release();
return;
}
/*
* CIOleUILinkContainre::FInit
*
* Purpose:
* Performs initialization on the object that might fail. In particular
* this creates an object of CLSID_LinksAssistant that helps in
* implementing this interface.
*
* Parameters:
* None
*
* Return Value:
* BOOL TRUE if successful, FALSE otherwise.
*/
BOOL CIOleUILinkContainer::FInit(void)
{
HRESULT hr;
hr=CoCreateInstance(CLSID_LinksAssistant, NULL, CLSCTX_INPROC_SERVER
, IID_IOleUILinkContainer, (LPLPVOID)&m_pDelIUILinks);
return SUCCEEDED(hr);
}
/*
* CIOleUILinkContainer::QueryInterface
* CIOleUILinkContainer::AddRef
* CIOleUILinkContainer::Release
*
* Purpose:
* IUnknown members for CIOleUILinkContainer object.
*/
STDMETHODIMP CIOleUILinkContainer::QueryInterface(REFIID riid, LPLPVOID ppv)
{
*ppv=NULL;
if (IsEqualIID(riid, IID_IUnknown)
|| IsEqualIID(riid, IID_IOleUILinkContainer))
{
*ppv=(LPVOID)this;
AddRef();
return NOERROR;
}
return ResultFromScode(E_NOINTERFACE);
}
STDMETHODIMP_(ULONG) CIOleUILinkContainer::AddRef(void)
{
return ++m_cRef;
}
STDMETHODIMP_(ULONG) CIOleUILinkContainer::Release(void)
{
ULONG cRefT;
cRefT=--m_cRef;
if (0L==m_cRef)
delete this;
return cRefT;
}
/*
* CIOleUILinkContainer::GetNextLink
*
* Purpose:
* Called when the Links dialog is filling its listbox. Here we
* need to return a key for the first link if dwLink is zero, then
* return the next links if it's non-zero.
*
* Parameters:
* dwLink DWORD last returned from this function. Zero if
* this is the first call to this function.
*
* Return Value:
* DWORD Some value that identifies this object. Zero stops
* the sequence such that this function is no longer called.
*/
STDMETHODIMP_(DWORD) CIOleUILinkContainer::GetNextLink(DWORD dwLink)
{
LPTENANT pTenant;
//If we're told to start the sequence, set index to zero.
if (0==dwLink)
m_iTenant=0;
/*
* On each subsequent call, find the next linked object in
* this document and return it. Make sure the index is incremented
* for the next time this function is called.
*/
for ( ; m_iTenant < m_pPage->m_cTenants; m_iTenant++)
{
if (m_pPage->FTenantGet(m_iTenant, &pTenant, FALSE))
{
if (TENANTTYPE_LINKEDOBJECT==pTenant->TypeGet())
{
m_iTenant++;
return (DWORD)pTenant;
}
}
}
//If we hit the end of list, this tells the dialog to stop.
return 0L;
}
/*
* CIOleUILinkContainer::SetLinkUpdateOptions
*
* Purpose:
* Informs the application to call IOleLink::SetUpdateOptions for
* the object identified by dwLink.
*
* Parameters:
* dwLink DWORD object identifier as returned from GetNextLink.
* dwOptions DWORD containing the new options.
*
* Return Value:
* HRESULT Return value of IOleLink::SetUpdateOptions.
*/
STDMETHODIMP CIOleUILinkContainer::SetLinkUpdateOptions(DWORD dwLink
, DWORD dwOptions)
{
LPOLELINK pIOleLink;
HRESULT hr;
if (NULL==dwLink)
return ResultFromScode(E_FAIL);
/*
* Your responsibility is to call the object's
* IOleLink::SetUpdateOptions function with dwOptions. Simple?
*
* For Patron we must first get the object pointer obtainable
* from the tenant's ObjectGet function, then QI for IOleLink.
*/
GetObjectInterface(dwLink, IID_IOleLink, (LPLPVOID)&pIOleLink);
hr=pIOleLink->SetUpdateOptions(dwOptions);
pIOleLink->Release();
m_fDirty=SUCCEEDED(hr);
return hr;
}
/*
* CIOleUILinkContainer::GetLinkUpdateOptions
*
* Purpose:
* Requests the container to call IOleLink::GetUpdateOptions for
* the object identified by dwLink.
*
* Parameters:
* dwLink DWORD identifying the object
* pdwOptions LPDWORD in which to store the options.
*
* Return Value:
* HRESULT Return value of IOleLink::GetUpdateOptions
*/
STDMETHODIMP CIOleUILinkContainer::GetLinkUpdateOptions(DWORD dwLink
, LPDWORD pdwOptions)
{
LPOLELINK pIOleLink;
HRESULT hr;
if (NULL==dwLink)
return ResultFromScode(E_FAIL);
GetObjectInterface(dwLink, IID_IOleLink, (LPLPVOID)&pIOleLink);
hr=pIOleLink->GetUpdateOptions(pdwOptions);
pIOleLink->Release();
return hr;
}
/*
* CIOleUILinkContainer::SetLinkSource
*
* Purpose:
* Changes the moniker to which an object is linked.
*
* Parameters:
* dwLink DWORD identifying the object in question.
* pszName LPSTR to the displayable name of the source.
* cchName ULONG length of the file portaion of pszName
* pchEaten ULONG FAR * in which to return the number of characters
* used in parsing pszDisplayName.
* fValidate BOOL indicating if we're to validate that the source
* exists first.
*
* Return Value:
* HRESULT NOERROR if successful, E_FAIL otherwise.
*/
STDMETHODIMP CIOleUILinkContainer::SetLinkSource(DWORD dwLink, LPSTR pszName
, ULONG cchName, ULONG FAR * pchEaten, BOOL fValidate)
{
LPTENANT pTenant=(LPTENANT)dwLink;
HRESULT hr;
LPOLELINK pIOleLink;
if (NULL==dwLink)
return ResultFromScode(E_FAIL);
//This is for use in GetLinkSource, below.
pTenant->m_fLinkAvail=FALSE;
GetObjectInterface(dwLink, IID_IOleLink, (LPLPVOID)&pIOleLink);
hr=m_pDelIUILinks->SetLinkSource((DWORD)pIOleLink, pszName
, cchName, pchEaten, fValidate);
pIOleLink->Release();
if (FAILED(hr))
return hr;
//hr will be S_FALSE if link is unavailable.
pTenant->Repaint();
pTenant->m_fLinkAvail=(NOERROR==hr);
m_fDirty=TRUE;
return NOERROR;
}
/*
* CIOleUILinkContainer::GetLinkSource
*
* Purpose:
* Retrieves various strings and values for this link source.
*
* Parameters:
* dwLink DWORD identifying the object affected.
* ppszName LPSTR FAR * in which to return the new source name
* pcchName ULONG FAR * in which to return the length of pszName
* ppszFullLink LPSTR FAR * in which to return the full name of
* the class of linked object.
* ppszShortLink LPSTR FAR * in which to return the short name of
* the class of linked object.
* pfSourceAvail BOOL FAR * in wh